<?php
include '../lib/BLL/TrungTamBLL.php';
include '../lib/BLL/DmMonHocBLL.php';
include '../lib/BLL/DonViHocVuBLL.php';
include '../lib/BLL/SinhVienBLL.php';
include '../lib/BLL/DmCaHocBLL.php';
include '../lib/BLL/HoiDongThiBLL.php';

$ma_donvi = $_POST['donvi'];
$hocvu = $_POST['dvhv'];
$ma_monhoc = $_POST['mon'];

$hoidong = new HoiDongThiBLL();
$hd = $hoidong->getHoiDong_indirect($ma_donvi, $hocvu);
$smarty->assign('hd',$hd);

$dv = new TrungTamBLL();
$mh = new DmMonHocBLL();
$dvhv = new DonViHocVuBLL();
$sv = new SinhVienBLL();
$cathi = new DmCaHocBLL();
$mahdthi = $hd->getma_hoidong();

//Get List SV
$sql = "SELECT dkm.ma_sv, dkm.ma_dkm, sv.hoten_sv, sv.ngaysinh_sv, dkm.ma_lopmon FROM tbl_dangkymon AS dkm
INNER JOIN tbl_sinhvien AS sv ON sv.ma_sv = dkm.ma_sv
WHERE ma_lopmon IN(SELECT lm.ma_lopmon FROM tbl_lopmon AS lm
INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lm.ma_lopmon = lmctdt.ma_lopmon
INNER JOIN  tbl_mon_ctdt AS mctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
INNER JOIN dm_monhoc AS mh ON mctdt.ma_monhoc = mh.madm_mh
WHERE lm.ma_trungtam = '$ma_donvi' AND lm.ma_donvihocvu = '$hocvu'
AND mh.madm_mh = '$ma_monhoc'
) AND dkm.ma_dkm NOT IN(SELECT ma_dkm FROM tbl_diemthi WHERE ma_dsthi IN(SELECT DISTINCT ma_dsthi FROM `tbl_dsthi` WHERE ma_hoidongthi = '$mahdthi' AND ma_mon_ctdt = '$ma_monhoc'))";
$svarr = $db->getList($sql);

$donvi = $dv->getTrungTamInfo($ma_donvi);
$monhoc = $mh->getDmMonHoc($ma_monhoc);
$ds_dvhv = $dvhv->getListDonViHocVu();
$ds_sv = $sv->getListSinhvien();
$ds_cathi = $cathi->getListDmCaHoc();

$smarty->assign('monhoc',$monhoc);
$smarty->assign('donvi',$donvi);
$smarty->assign('sinhvien',$svarr);
$smarty->assign('hocvu',$hocvu);
$smarty->assign('ds_sv',$ds_sv);
$smarty->assign('ds_cathi',$ds_cathi);
$smarty->assign('date',date('Y-m-d'));

$smarty->display('tochucthi/lapdsthi.tpl');
?>